package com.wuyancheng.blog.controller;

import com.wuyancheng.blog.pojo.Article;
import com.wuyancheng.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


@Controller
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 查询文章信息
     * @param model
     * @param pageNum 第几页 默认从0开始
     * @param pageSize 页面展示的条数
     * @return
     */
    @RequestMapping("/index")
    public String queryArticle(Model model, @RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "3") int pageSize){
        List<Article> articleList = articleService.queryArticle(pageNum,pageSize);
        int count = articleService.countArticle();
        int totalPage = count / pageSize;
        model.addAttribute("articleList", articleList);
        model.addAttribute("totalPage", totalPage);
        model.addAttribute("pageNum", pageNum);
        return "/client/index";
    }
}
